/***************************************************************************************
 The copyright in this software is being made available under the BSD License, included
 below. This software may be subject to other third party rights,including patent rights,
 and no such rights are granted under this license.

 Regents of the Tsinghua University, Peking University, Zhejiang University, HKUST
 Tsinghua University, Peking University, Zhejiang University, HKUST 2011

 Copyright (c) 2011, Regents of the Tsinghua University, Peking University, Zhejiang
 University, HKUST. All Rights Reserved.

 Redistribution and use in source and binary forms, with or without modification, are
 permitted provided that the following conditions are met:
   * Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
   * Neither the names of the copyright holders nor the names of its
     contributors may be used to endorse or promote products derived from this
     software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 OF SUCH DAMAGE.
***************************************************************************************/


#ifndef  _QCODER_H_
#define  _QCODER_H_

#include "global.h"

prob_state_t eq_prob_fsm[1] ;
prob_state_t standard_prob_fsm[113];

void qcoder_init( qcoder_env_t* qcoder, bitstream_t* currStream );
int qcoder_decode_symbol( qcoder_env_t* qcoder, prob_context_t* context );
void qcoder_flush( qcoder_env_t* qcoder );


int aricod_decode_flag( qcoder_env_t* qcoder, prob_context_t* flag_context );
int aricod_decode_fixed_bits( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int nBits );
int aricod_decode_signed_fixed_bits( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int nBits );
int aricod_decode_unary( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts );
int aricod_decode_signed_unary( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts );
int aricod_decode_trunary( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int maxValue );
int aricod_decode_expGolomb( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int k );
int aricod_decode_signed_expGolomb( qcoder_env_t* qcoder, prob_context_t* contexts, int num_contexts, int k );

int qcoder_decode_eobflag_8x8( qcoder_env_t* qcoder, int ipos );
int qcoder_decode_eobflag_4x4( qcoder_env_t* qcoder, int ipos );
int qcoder_decode_eobflag_chroma( qcoder_env_t* qcoder, int ipos );

int qcoder_decode_eobflag( qcoder_env_t* qcoder );
//cbp is not used, we are using eob to indicate the end of a block
//int qcoder_decode_intra_cbp(qcoder_env_t* qcoder);
//int qcoder_decode_inter_cbp(qcoder_env_t* qcoder);

int qcoder_decode_inter_skip( qcoder_env_t* qcoder );
int qcoder_decode_Direction( qcoder_env_t* qcoder, int type );

int qcoder_decode_delta_qp( qcoder_env_t* qcoder );
int qcoder_decode_intra_luma_mode( qcoder_env_t* qcoder );
int qcoder_decode_intra_chroma_mode( qcoder_env_t* qcoder );
int qcoder_decode_inter_ref( qcoder_env_t* qcoder );

int qcoder_decode_luma_b8x8_coeff( qcoder_env_t* qcoder, int idx, int intra );
int qcoder_decode_chroma_b8x8_coeff( qcoder_env_t* qcoder, int idx, int intra );
int qcoder_decode_luma_b4x4_coeff( qcoder_env_t* qcoder, int idx, int intra );
int qcoder_decode_luma_b16x16_coeff( qcoder_env_t* qcoder, int idx, int intra );

int qcoder_decode_mvdx( qcoder_env_t* qcoder );
int qcoder_decode_mvdy( qcoder_env_t* qcoder );
int qcoder_decode_mvdx_num( qcoder_env_t* qcoder, int cnt );
int qcoder_decode_mvdy_num( qcoder_env_t* qcoder, int cnt );

int qcoder_decode_blocksize( qcoder_env_t* qcoder );
int qcoder_decode_subblocksize( qcoder_env_t* qcoder );
int qcoder_decode_pred_direction( qcoder_env_t* qcoder );

#endif


